<?PHP
import('iforum.dao.mysql.MySQLDAO');
import('iforum.common.Util');
import('iforum.web.iForumWebAppContext');

/**
 * @package  iforum.dao.mysql
 * @author   iCer <iCer@justdn.com>
 * @version  $Id: MySQLConfigurationDAO.php,v 1.1.1.1 2005/03/03 04:53:17 icer Exp $
 */
 class MySQLConfigurationDAO extends MySQLDAO 
 {
 	var $context;
	var $registry;
	var $request;
	var $registryValues;

	function MySQLConfigurationDAO()
	{
		$this->__constract();
	}

	function __constract()
	{
		$this->context = &Singleton::instance('iForumWebAppContext');
		$this->registry = &$this->context->getRegistry();
		$this->request  = &$this->context->getRequest();
		$this->registryValues = &$this->registry->getRegistryValues();
	}	
		
 	/**
 	 * get all configuration data from db
 	 * @return mixed
 	 */
 	function &getConfiguration()
 	{
		
		$sql = 'select * from '.$this->registryValues['data_table']['configuration'].' order by conf_group';
		return $this->_dbAdapter->execute($sql);	
 	}
 	
 	/**
 	 * @param array $configEntry
 	 */
 	function updateConfiguration($configEntry)
 	{
 		
 		$where = "wnere conf_group='".$configEntry['conf_group']
 				."' and conf_key='".$configEntry['conf_key']."'";
 		$sql = getUpdateSql($configEntry, $this->registryValues['data_table']['configuration'], $where);
 		$this->_dbAdapter->execute($sql);
 	}

 	/**
 	 * @param array $configEntry
 	 */ 	
 	function addConfiguration($configEntry)
 	{
  		
 		$sql = getInsertSql($configEntry, $this->registryValues['data_table']['configuration']);
 		$this->_dbAdapter->execute($sql);		
 	}
 	
 	/**
 	 * @param string group
 	 * @param string key
 	 */
 	function removeEntry($group,$key)
 	{
 		
 		$sql = "delete from ".$this->registryValues['data_table']['configuration']
 			." where conf_group='".$group
 			."' and conf_key='".$key."'";
 		$this->_dbAdapter->execute($sql);
 	}
 	
 	function removeGroup($group)
 	{
 		
 		$sql = "delete from ".$this->registryValues['data_table']['configuration']
 			." where conf_group='".$group."'";
 		$this->_dbAdapter->execute($sql);
 	}
 }

?>